<template>
	<view class="knmnknmert">
		<view class="fz36 cf">
			请编辑您的密码
		</view>
		<view class="mt20 z9 fz26">
			新密码：不少于6位数，字母、数字、下划线组合
		</view>
		<input value="" @input="jjnknxer" password v-model="passetta" placeholder="" class="fz30 beertert mt40" />
		<view class="mt100 gedrert" :class="ijnsd">
			<view class="">
			</view>
			<view class="">
			</view>
			<view class="">
			</view>
		</view>
		<view class="fz26 cf cen  mt20">
			{{isjnd}}
		</view>
		<view class="mt80 z9 fz26">
			确认密码
		</view>
		<input value="" password v-model="passettb" placeholder="" class="fz30 beertert mt40" />
		<view class="mt60 hjjnnxeert cf cen mt180" @tap="qyuehhsd">
			确定
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				passetta: '',
				passettb: '',
				isjnd: '不安全',
				ijnsd: '',
				type:""//1为找回密码
			}
		},
		components: {},
		onLoad(e) {
			this.type=e.type
		},
		methods: {
			// 判断密码安全等级
			AnalyzePasswordSecurityLevel(password) {
			    var securityLevelFlag = 0;
			    if (password.length < 6) {
			        return 0;
			    }
			    else {
			        if (/[a-z]/.test(password)){
			            securityLevelFlag++;    //lowercase
			        }
			        if (/[A-Z]/.test(password)){
			            securityLevelFlag++;    //uppercase
			        } 
			        if(/[0-9]/.test(password)){
			            securityLevelFlag++;    //digital
			        }
			        if(this.containSpecialChar(password)){
						uni.showToast({
							title:'密码不能包含特殊字符',
							icon:'none'
						})
						this.passetta = ''
						return false
			            // securityLevelFlag++;    //specialcase
			        }
			        return securityLevelFlag;
			    }
			},
			 containSpecialChar(str)   
			{   
			    var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);
			    return (containSpecial.test(str));   
			},
			jjnknxer() {
				this.isjnd = '不安全'
				this.ijnsd = ''
				this.checklevel = this.AnalyzePasswordSecurityLevel(this.passetta)
				if (this.checklevel == 1) {
					this.ijnsd = 'aa'
				}
				if (this.checklevel == 2) {
					this.isjnd = '一般'
					this.ijnsd = 'ab'
				}
				if (this.checklevel == 3) {
					this.isjnd = '安全'
					this.ijnsd = 'ac'
				}
			},
			async qyuehhsd() {
				// uni.navigateTo({
				// 	url:"LoginAndRegistration"
				// })
				if (!this.passetta) {
					uni.showToast({
						title: '请输入密码',
						icon: "none"
					})
					return
				}
				if (this.passetta.length<6) {
					uni.showToast({
						title: '密码长度须大于六位',
						icon: "none"
					})
					return
				}
				if (!this.passettb) {
					uni.showToast({
						title: '请输入确认密码',
						icon: "none"
					})
					return
				}
				if (this.passetta != this.passettb) {
					uni.showToast({
						title: '两次密码输入不一致',
						icon: "none"
					})
					return
				}
				if(this.type==1){
					let retrieve=this.$store.state.userskey
					retrieve.password = this.passetta
					retrieve.password_confirmation=this.passettb
					delete retrieve['phone']						
					let pwd = await this.get("/api/forget", retrieve,"PUT")
					uni.navigateTo({
						url:"Login"
					})
					
				}else{
					let jhhsd = this.$store.state.userskey
					jhhsd.password = this.passettb
					delete jhhsd['phone']
					this.$store.commit('setuserskey', jhhsd)
					let jhsd = await this.post("/api/users", jhhsd)
					uni.showLoading()
					uni.setStorageSync('access_token',jhsd.token_type+jhsd.access_token)
					let sdee = new Date().getTime()
					uni.setStorageSync('times', sdee)
					uni.setStorageSync('expires_in', jhsd.expires_in)
					// var jsModule = uni.requireNativePlugin("MyModule")
					this.dqRegisterInitProject(jhsd.uid,
						(rets) => {
							// uni.showToast({
							// 	title: '设备注册用户',
							// 	icon:"none"
							// });
					})
					uni.hideLoading()
					uni.switchTab({
						url:"/pages/zhongjianbtn/index"
					})
				}
			}
		},
		mounted() {}
	}
</script>
<style scoped>
	.gedrert {
		display: grid;
		grid-template-columns: repeat(3, 1fr);
		grid-column-gap: 20upx;
	}

	.gedrert view {
		background-color: #1689D5;
		height: 6upx;
		opacity: 0.1;
	}

	.gedrert.aa view:nth-child(1) {
		opacity: 1;
	}

	.gedrert.ab view:nth-child(1) {
		opacity: 1;
	}

	.gedrert.ab view:nth-child(2) {
		opacity: 1;
	}

	.gedrert.ac view {
		opacity: 1;
	}

	.mt180 {
		margin-top: 180upx !important;
	}
</style>